//
//  OHA_PublicMethod.m
//  OneHourArrvie
//
//  Created by Sunny on 16/12/9.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "base_PublicMethod.h"

static base_PublicMethod *publicMethod = nil;
@implementation base_PublicMethod

//UIButton
+(UIButton *)creatButtonWithBackgroundImage:(NSString *)backgroudImage WithBackgroundHighImage:(NSString *)highImage WithBackgroundColor:(UIColor *)backgroundColor WithTitle:(NSString *)title WithTextColor:(UIColor *)textcolor  WithtextFont:(UIFont *)font WithaddView:(UIView *)addView Withtarget:(id)target Withaction:(SEL)action{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:backgroudImage] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateSelected];
    [btn setBackgroundColor:backgroundColor];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:textcolor forState:UIControlStateNormal];
    btn.titleLabel.font = font;
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [addView addSubview:btn];
    return btn;
}

+(UIButton *)creatButtonWithBackgroundImage:(NSString *)image WithaddView:(UIView *)addView Withtarget:(id)target Withaction:(SEL)action{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [addView addSubview:btn];
    return btn;
}

+(UIButton *)creatButtonWithTitle:(NSString *)title WithTextFont:(UIFont *)font WithTitleColor:(UIColor *)textcolor WithBackgroundColor:(UIColor *)backgroundColor WithAddView:(UIView *)addView WithTarget:(id)target WithAction:(SEL)action{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setBackgroundColor:backgroundColor];
    [btn setTitleColor:textcolor forState:UIControlStateNormal];
    btn.titleLabel.font = font;
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [addView addSubview:btn];
    return btn;

}

//UILabel
+(UILabel *)creatLabelWithText:(NSString *)text WithFont:(UIFont *)font WithTextColor:(UIColor *)color WithTextAlignment:(NSInteger)count WithBackgroundColor:(UIColor *)backgroundColor WithAddView:(UIView *)addView WithnumberOfLines:(NSInteger)lines{
    UILabel *label = [[UILabel alloc]init];
    label.text = text;
    label.font = font;
    label.textColor = color;
    label.textAlignment = count;
    label.backgroundColor = backgroundColor;
    label.numberOfLines = lines;
    [addView addSubview:label];
    return label;
}

//UIView
+(UIView *)creatViewWithBackgroundColor:(UIColor *)color WithAddView:(UIView *)addView{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = color;
    [addView addSubview:view];
    return view;
}

//UITextField
+(UITextField *)creatTextFieldWithPlaceHolder:(NSString *)placeholder  WithTextFont:(UIFont *)font WithTextClearButtonMode:(NSInteger )count WithAddView:(UIView *)addView {
    UITextField *textField = [[UITextField alloc]init];
    textField.placeholder = placeholder;
    textField.font = font;
    textField.clearButtonMode = count;
    [addView addSubview:textField];
    return textField;
}

//UIImageView
+(UIImageView *)creatImageViewWithImage:(NSString *)imageName  WithAddView:(UIView *)addView {
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:imageName];
    [addView addSubview:imageView];
    return imageView;
}

#pragma mark --- 改变一个字符串中某个的颜色 ---
+(void)setTextColor:(UILabel *)label AndRange:(NSRange)range AndColor:(UIColor *)color
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:label.text ];
    [str addAttribute:NSForegroundColorAttributeName value:color range:range];
    label.attributedText = str;
}
#pragma mark --- 改变一个字符串中某个的大小 ---
+(NSMutableAttributedString *)OHA_setTextColor:(NSString *)label AndRange:(NSRange)range AndColor:(UIColor *)color
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:label ];
    [str addAttribute:NSForegroundColorAttributeName value:color range:range];
    return str;
    
}


+(void)setTextFont:(UILabel *)label AndRange:(NSRange)range AndFont:(UIFont *)font
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:label.text ];
    [str addAttribute:NSFontAttributeName value:font range:range];
    label.attributedText = str;
    
    
}



@end
